//
//  InviteFriend.m
//  FB_skd
//
//  Created by Le Thanh Hai on 4/21/13.
//  Copyright (c) 2013 Le Thanh Hai. All rights reserved.
//

#import "InviteFriend.h"

@implementation InviteFriend
@synthesize dataSource;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super initWithCoder:aDecoder]) {
        UIView *view = [[[NSBundle mainBundle] loadNibNamed:@"InviteFriend" owner:self options:nil] objectAtIndex:0];
        [view setFrame:[self bounds]];
        [self addSubview:view];
    }
    return self;
}

#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dataSource.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 32.5f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static UINib *cellLoader;
    if (!cellLoader) {
        cellLoader = [[UINib nibWithNibName:@"CellInvite" bundle:[NSBundle mainBundle]] retain];
    }
    CellInvite *cell = (CellInvite*)[tableView dequeueReusableCellWithIdentifier:@"CellInvite"];
    if (cell == nil) {
        NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
        cell = [topLevelItems objectAtIndex:0];
    }
    
    cell.name.text = [[dataSource objectAtIndex:indexPath.row] objectForKey:@"name"];
    cell.facebookId = [NSString stringWithFormat:@"%@", [[dataSource objectAtIndex:indexPath.row] objectForKey:@"id"]];

    return cell;
}

-(void)setDataSource:(NSMutableArray *)dataSource_
{
    dataSource = [dataSource_ retain];
    [tableRanking reloadData];
}

@end
